from django.core.management.base import BaseCommand
from navigation.models import NavigationGroup, NavigationLink

class Command(BaseCommand):
    help = '初始化或更新导航数据'

    def handle(self, *args, **kwargs):
        self.stdout.write('开始初始化或更新导航数据...')
        
        # 清空现有数据
        self.stdout.write('清空现有数据...')
        NavigationLink.objects.all().delete()
        NavigationGroup.objects.all().delete()
        
        # 业务系统分组
        business_group = NavigationGroup.objects.create(
            title='业务系统',
            order=1
        )
        NavigationLink.objects.create(
            group=business_group,
            name='官网',
            url='https://www.example.com',
            icon='fas fa-globe',
            description='公司官方网站',
            order=1
        )
        NavigationLink.objects.create(
            group=business_group,
            name='管理后台',
            url='https://admin.example.com',
            icon='fas fa-cogs',
            description='业务管理系统',
            order=2
        )

        # 运维工具分组
        devops_group = NavigationGroup.objects.create(
            title='运维工具',
            order=2
        )
        devops_links = [
            {
                'name': 'GitLab',
                'url': 'https://gitlab.example.com',
                'icon': 'fab fa-gitlab',
                'description': '代码仓库管理平台',
                'order': 1
            },
            {
                'name': 'Jenkins',
                'url': 'https://jenkins.example.com',
                'icon': 'fas fa-rocket',
                'description': '持续集成/持续部署平台',
                'order': 2
            },
            {
                'name': 'Kuboard',
                'url': 'https://kuboard.example.com',
                'icon': 'fas fa-dharmachakra',
                'description': 'Kubernetes 管理界面',
                'order': 3
            }
        ]
        for link_data in devops_links:
            NavigationLink.objects.create(group=devops_group, **link_data)

        # 安全与监控分组
        security_group = NavigationGroup.objects.create(
            title='安全与监控',
            order=3
        )
        security_links = [
            {
                'name': '堡垒机',
                'url': 'https://bastion.example.com',
                'icon': 'fas fa-shield-alt',
                'description': '运维安全接入平台',
                'order': 1
            },
            {
                'name': 'WAF',
                'url': 'https://waf.example.com',
                'icon': 'fas fa-fire-alt',
                'description': 'Web应用防火墙',
                'order': 2
            },
            {
                'name': '日志系统',
                'url': 'https://logs.example.com',
                'icon': 'fas fa-clipboard-list',
                'description': '集中式日志管理平台',
                'order': 3
            }
        ]
        for link_data in security_links:
            NavigationLink.objects.create(group=security_group, **link_data)

        # 数据库工具分组
        db_group = NavigationGroup.objects.create(
            title='数据库工具',
            order=4
        )
        NavigationLink.objects.create(
            group=db_group,
            name='SQL平台',
            url='https://sql.example.com',
            icon='fas fa-database',
            description='数据库管理与SQL审核平台',
            order=1
        )

        # 文档与知识库分组
        docs_group = NavigationGroup.objects.create(
            title='文档与知识库',
            order=5
        )
        docs_links = [
            {
                'name': 'Wiki',
                'url': 'https://wiki.example.com',
                'icon': 'fas fa-book',
                'description': '团队知识库',
                'order': 1
            },
            {
                'name': 'API文档',
                'url': 'https://api-docs.example.com',
                'icon': 'fas fa-file-code',
                'description': '接口文档中心',
                'order': 2
            }
        ]
        for link_data in docs_links:
            NavigationLink.objects.create(group=docs_group, **link_data)

        self.stdout.write(self.style.SUCCESS('成功初始化导航数据'))
